#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>

using namespace cv;

/// Global variables
Mat src, erosion_dst, dilation_dst, src_gray, dst;
string savePath, fileName;
int erosion_elem = 0;
int erosion_size = 0;
int dilation_elem = 0;
int dilation_size = 5;
int const max_elem = 2;
int const max_kernel_size = 21;

/** Function Headers */
void Erosion(int, void*);
void Dilation(int, void*);

/** @function main */
void editImage(string origin, string destination, string name) {
	fileName = name;
	savePath = destination;
	src = imread(origin);
	cvtColor(src, src_gray, CV_RGB2GRAY);
	Dilation(0, 0);
}




/** @function Dilation */
void Dilation(int, void*)
{
	int dilation_type;
	if (dilation_elem == 0){ dilation_type = MORPH_RECT; }
	else if (dilation_elem == 1){ dilation_type = MORPH_CROSS; }
	else if (dilation_elem == 2) { dilation_type = MORPH_ELLIPSE; }
	dilation_size = 2;
	Mat element = getStructuringElement(dilation_type,
		Size(2 * dilation_size + 1, 2 * dilation_size + 1),
		Point(dilation_size, dilation_size));
	threshold(src_gray, dst, 127, 255, 0);
	dilate(dst, dilation_dst, element);
	imwrite(savePath + fileName, dilation_dst);
}

void perfeccionarImagen(string origin, string destination, string name) {
	fileName = name;
	savePath = destination;
	src = imread(origin);
	cvtColor(src, src_gray, CV_RGB2GRAY);
	threshold(src_gray, dst, 127, 255, 0);
	/*
	img = cv2.imread('j.png', 0)
	kernel = np.ones((5, 5), np.uint8)
	mat erosion = erode(img, kernel, iterations = 1)
	dilate(src_gray, dst, element);*/
	imwrite(destination + name, dst);
}

